<?php
/**
 * ProductTargetingCategoriesApi
 * PHP version 5
 *
 * @category Class
 * @package  AmazonAdvertisingApi
 * @author   vv_guo
 * @link    https://gitee.com/HuaLiLiDeDiDiao/amazon-advertising-api
 */

/**
 * Sponsored Brands campaign management
 *
 * Create and manage Sponsored Brands campaigns.   To learn more about Sponsored Brands campaigns, see:   - [Sponsored Brands overview](guides/sponsored-brands/overview)  - [Sponsored Brands campaign structure](guides/sponsored-brands/campaigns/structure)  - [Get started with Sponsored Brands campaigns](guides/sponsored-brands/campaigns/get-started-with-campaigns)
 *
 * OpenAPI spec version: 4.0
 * 
 * Generated by:https://gitee.com/HuaLiLiDeDiDiao/amazon-advertising-api.git
 * AmazonAdvertisingApi Codegen version: 3.0.51
 */
/**
 * NOTE: This class is auto generated by the AmazonAdvertisingApi code generator program.
 *https://gitee.com/HuaLiLiDeDiDiao/amazon-advertising-api
 * Do not edit the class manually.
 */

namespace AmazonAdvertisingApi\Api;

use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\MultipartStream;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\RequestOptions;
use AmazonAdvertisingApi\ApiException;
use AmazonAdvertisingApi\Configuration;
use AmazonAdvertisingApi\HeaderSelector;
use AmazonAdvertisingApi\ObjectSerializer;

/**
 * ProductTargetingCategoriesApi Class Doc Comment
 *
 * @category Class
 * @package  AmazonAdvertisingApi
 * @author   vv_guo
 * @link    https://gitee.com/HuaLiLiDeDiDiao/amazon-advertising-api
 */
class ProductTargetingCategoriesApi
{
    /**
     * @var ClientInterface
     */
    protected $client;

    /**
     * @var Configuration
     */
    protected $config;

    /**
     * @var HeaderSelector
     */
    protected $headerSelector;

    /**
     * @param ClientInterface $client
     * @param Configuration   $config
     * @param HeaderSelector  $selector
     */
    public function __construct(
        ClientInterface $client = null,
        Configuration $config = null,
        HeaderSelector $selector = null
    ) {
        $this->client = $client ?: new Client();
        $this->config = $config ?: new Configuration();
        $this->headerSelector = $selector ?: new HeaderSelector();
    }

    /**
     * @return Configuration
     */
    public function getConfig()
    {
        return $this->config;
    }

    /**
     * Operation sBTargetingGetRefinementsForCategory
     *
     * Get refinements for category
     *
     * @param  string $category_refinement_id The category refinement id. Please use /sb/targets/categories or /sb/recommendations/targets/category to retrieve category IDs. (required)
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a &#x60;Login with Amazon&#x60; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header and choose profile id &#x60;profileId&#x60; from the response to pass it as input. (required)
     * @param  \AmazonAdvertisingApi\Model\SBTargetingLocale $locale The locale to which the caller wishes to translate the targetable categories or refinements to. For example, if the caller wishes to receive the targetable categories in Simplified Chinese, the locale parameter should be set to zh_CN. If no locale is provided, the returned tagetable categories will be in the default language of the marketplace. (optional)
     * @param  string $next_token Operations that return paginated results include a pagination token in this field. To retrieve the next page of results, call the same operation and specify this token in the request. If the &#x60;NextToken&#x60; field is empty, there are no further results. (optional)
     *
     * @throws \AmazonAdvertisingApi\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \AmazonAdvertisingApi\Model\SBTargetingGetRefinementsForCategoryResponseContent
     */
    public function sBTargetingGetRefinementsForCategory($category_refinement_id, $amazon_advertising_api_client_id, $amazon_advertising_api_scope, $locale = null, $next_token = null)
    {
        list($response) = $this->sBTargetingGetRefinementsForCategoryWithHttpInfo($category_refinement_id, $amazon_advertising_api_client_id, $amazon_advertising_api_scope, $locale, $next_token);
        return $response;
    }

    /**
     * Operation sBTargetingGetRefinementsForCategoryWithHttpInfo
     *
     * Get refinements for category
     *
     * @param  string $category_refinement_id The category refinement id. Please use /sb/targets/categories or /sb/recommendations/targets/category to retrieve category IDs. (required)
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a &#x60;Login with Amazon&#x60; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header and choose profile id &#x60;profileId&#x60; from the response to pass it as input. (required)
     * @param  \AmazonAdvertisingApi\Model\SBTargetingLocale $locale The locale to which the caller wishes to translate the targetable categories or refinements to. For example, if the caller wishes to receive the targetable categories in Simplified Chinese, the locale parameter should be set to zh_CN. If no locale is provided, the returned tagetable categories will be in the default language of the marketplace. (optional)
     * @param  string $next_token Operations that return paginated results include a pagination token in this field. To retrieve the next page of results, call the same operation and specify this token in the request. If the &#x60;NextToken&#x60; field is empty, there are no further results. (optional)
     *
     * @throws \AmazonAdvertisingApi\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \AmazonAdvertisingApi\Model\SBTargetingGetRefinementsForCategoryResponseContent, HTTP status code, HTTP response headers (array of strings)
     */
    public function sBTargetingGetRefinementsForCategoryWithHttpInfo($category_refinement_id, $amazon_advertising_api_client_id, $amazon_advertising_api_scope, $locale = null, $next_token = null)
    {
        $returnType = '\AmazonAdvertisingApi\Model\SBTargetingGetRefinementsForCategoryResponseContent';
        $request = $this->sBTargetingGetRefinementsForCategoryRequest($category_refinement_id, $amazon_advertising_api_client_id, $amazon_advertising_api_scope, $locale, $next_token);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if (!in_array($returnType, ['string','integer','bool'])) {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\SBTargetingGetRefinementsForCategoryResponseContent',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\SBTargetingBadRequestExceptionResponseContent',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\SBTargetingUnauthorizedExceptionResponseContent',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 429:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\SBTargetingThrottlingExceptionResponseContent',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\SBTargetingInternalServerExceptionResponseContent',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation sBTargetingGetRefinementsForCategoryAsync
     *
     * Get refinements for category
     *
     * @param  string $category_refinement_id The category refinement id. Please use /sb/targets/categories or /sb/recommendations/targets/category to retrieve category IDs. (required)
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a &#x60;Login with Amazon&#x60; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header and choose profile id &#x60;profileId&#x60; from the response to pass it as input. (required)
     * @param  \AmazonAdvertisingApi\Model\SBTargetingLocale $locale The locale to which the caller wishes to translate the targetable categories or refinements to. For example, if the caller wishes to receive the targetable categories in Simplified Chinese, the locale parameter should be set to zh_CN. If no locale is provided, the returned tagetable categories will be in the default language of the marketplace. (optional)
     * @param  string $next_token Operations that return paginated results include a pagination token in this field. To retrieve the next page of results, call the same operation and specify this token in the request. If the &#x60;NextToken&#x60; field is empty, there are no further results. (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function sBTargetingGetRefinementsForCategoryAsync($category_refinement_id, $amazon_advertising_api_client_id, $amazon_advertising_api_scope, $locale = null, $next_token = null)
    {
        return $this->sBTargetingGetRefinementsForCategoryAsyncWithHttpInfo($category_refinement_id, $amazon_advertising_api_client_id, $amazon_advertising_api_scope, $locale, $next_token)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation sBTargetingGetRefinementsForCategoryAsyncWithHttpInfo
     *
     * Get refinements for category
     *
     * @param  string $category_refinement_id The category refinement id. Please use /sb/targets/categories or /sb/recommendations/targets/category to retrieve category IDs. (required)
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a &#x60;Login with Amazon&#x60; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header and choose profile id &#x60;profileId&#x60; from the response to pass it as input. (required)
     * @param  \AmazonAdvertisingApi\Model\SBTargetingLocale $locale The locale to which the caller wishes to translate the targetable categories or refinements to. For example, if the caller wishes to receive the targetable categories in Simplified Chinese, the locale parameter should be set to zh_CN. If no locale is provided, the returned tagetable categories will be in the default language of the marketplace. (optional)
     * @param  string $next_token Operations that return paginated results include a pagination token in this field. To retrieve the next page of results, call the same operation and specify this token in the request. If the &#x60;NextToken&#x60; field is empty, there are no further results. (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function sBTargetingGetRefinementsForCategoryAsyncWithHttpInfo($category_refinement_id, $amazon_advertising_api_client_id, $amazon_advertising_api_scope, $locale = null, $next_token = null)
    {
        $returnType = '\AmazonAdvertisingApi\Model\SBTargetingGetRefinementsForCategoryResponseContent';
        $request = $this->sBTargetingGetRefinementsForCategoryRequest($category_refinement_id, $amazon_advertising_api_client_id, $amazon_advertising_api_scope, $locale, $next_token);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'sBTargetingGetRefinementsForCategory'
     *
     * @param  string $category_refinement_id The category refinement id. Please use /sb/targets/categories or /sb/recommendations/targets/category to retrieve category IDs. (required)
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a &#x60;Login with Amazon&#x60; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header and choose profile id &#x60;profileId&#x60; from the response to pass it as input. (required)
     * @param  \AmazonAdvertisingApi\Model\SBTargetingLocale $locale The locale to which the caller wishes to translate the targetable categories or refinements to. For example, if the caller wishes to receive the targetable categories in Simplified Chinese, the locale parameter should be set to zh_CN. If no locale is provided, the returned tagetable categories will be in the default language of the marketplace. (optional)
     * @param  string $next_token Operations that return paginated results include a pagination token in this field. To retrieve the next page of results, call the same operation and specify this token in the request. If the &#x60;NextToken&#x60; field is empty, there are no further results. (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function sBTargetingGetRefinementsForCategoryRequest($category_refinement_id, $amazon_advertising_api_client_id, $amazon_advertising_api_scope, $locale = null, $next_token = null)
    {
        // verify the required parameter 'category_refinement_id' is set
        if ($category_refinement_id === null || (is_array($category_refinement_id) && count($category_refinement_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $category_refinement_id when calling sBTargetingGetRefinementsForCategory'
            );
        }
        // verify the required parameter 'amazon_advertising_api_client_id' is set
        if ($amazon_advertising_api_client_id === null || (is_array($amazon_advertising_api_client_id) && count($amazon_advertising_api_client_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_advertising_api_client_id when calling sBTargetingGetRefinementsForCategory'
            );
        }
        // verify the required parameter 'amazon_advertising_api_scope' is set
        if ($amazon_advertising_api_scope === null || (is_array($amazon_advertising_api_scope) && count($amazon_advertising_api_scope) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_advertising_api_scope when calling sBTargetingGetRefinementsForCategory'
            );
        }

        $resourcePath = '/sb/targets/categories/{categoryRefinementId}/refinements';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        if ($locale !== null) {
            $queryParams['locale'] = ObjectSerializer::toQueryValue($locale, null);
        }
        // query params
        if ($next_token !== null) {
            $queryParams['nextToken'] = ObjectSerializer::toQueryValue($next_token, null);
        }
        // header params
        if ($amazon_advertising_api_client_id !== null) {
            $headerParams['Amazon-Advertising-API-ClientId'] = ObjectSerializer::toHeaderValue($amazon_advertising_api_client_id);
        }
        // header params
        if ($amazon_advertising_api_scope !== null) {
            $headerParams['Amazon-Advertising-API-Scope'] = ObjectSerializer::toHeaderValue($amazon_advertising_api_scope);
        }

        // path params
        if ($category_refinement_id !== null) {
            $resourcePath = str_replace(
                '{' . 'categoryRefinementId' . '}',
                ObjectSerializer::toPathValue($category_refinement_id),
                $resourcePath
            );
        }

        // body params
        $_tempBody = null;

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/vnd.sbtargeting.v4+json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/vnd.sbtargeting.v4+json'],
                []
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\Query::build($formParams);
            }
        }


        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\Query::build($queryParams);
        return new Request(
            'GET',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation sBTargetingGetTargetableASINCounts
     *
     * Get number of products in a category
     *
     * @param  \AmazonAdvertisingApi\Model\SBTargetingGetTargetableASINCountsRequestContent $body body (required)
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a &#x60;Login with Amazon&#x60; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header and choose profile id &#x60;profileId&#x60; from the response to pass it as input. (required)
     *
     * @throws \AmazonAdvertisingApi\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \AmazonAdvertisingApi\Model\SBTargetingGetTargetableASINCountsResponseContent
     */
    public function sBTargetingGetTargetableASINCounts($body, $amazon_advertising_api_client_id, $amazon_advertising_api_scope)
    {
        list($response) = $this->sBTargetingGetTargetableASINCountsWithHttpInfo($body, $amazon_advertising_api_client_id, $amazon_advertising_api_scope);
        return $response;
    }

    /**
     * Operation sBTargetingGetTargetableASINCountsWithHttpInfo
     *
     * Get number of products in a category
     *
     * @param  \AmazonAdvertisingApi\Model\SBTargetingGetTargetableASINCountsRequestContent $body (required)
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a &#x60;Login with Amazon&#x60; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header and choose profile id &#x60;profileId&#x60; from the response to pass it as input. (required)
     *
     * @throws \AmazonAdvertisingApi\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \AmazonAdvertisingApi\Model\SBTargetingGetTargetableASINCountsResponseContent, HTTP status code, HTTP response headers (array of strings)
     */
    public function sBTargetingGetTargetableASINCountsWithHttpInfo($body, $amazon_advertising_api_client_id, $amazon_advertising_api_scope)
    {
        $returnType = '\AmazonAdvertisingApi\Model\SBTargetingGetTargetableASINCountsResponseContent';
        $request = $this->sBTargetingGetTargetableASINCountsRequest($body, $amazon_advertising_api_client_id, $amazon_advertising_api_scope);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if (!in_array($returnType, ['string','integer','bool'])) {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\SBTargetingGetTargetableASINCountsResponseContent',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\SBTargetingBadRequestExceptionResponseContent',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\SBTargetingUnauthorizedExceptionResponseContent',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 422:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\SBTargetingUnprocessableEntityExceptionResponseContent',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 429:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\SBTargetingThrottlingExceptionResponseContent',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\SBTargetingInternalServerExceptionResponseContent',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation sBTargetingGetTargetableASINCountsAsync
     *
     * Get number of products in a category
     *
     * @param  \AmazonAdvertisingApi\Model\SBTargetingGetTargetableASINCountsRequestContent $body (required)
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a &#x60;Login with Amazon&#x60; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header and choose profile id &#x60;profileId&#x60; from the response to pass it as input. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function sBTargetingGetTargetableASINCountsAsync($body, $amazon_advertising_api_client_id, $amazon_advertising_api_scope)
    {
        return $this->sBTargetingGetTargetableASINCountsAsyncWithHttpInfo($body, $amazon_advertising_api_client_id, $amazon_advertising_api_scope)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation sBTargetingGetTargetableASINCountsAsyncWithHttpInfo
     *
     * Get number of products in a category
     *
     * @param  \AmazonAdvertisingApi\Model\SBTargetingGetTargetableASINCountsRequestContent $body (required)
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a &#x60;Login with Amazon&#x60; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header and choose profile id &#x60;profileId&#x60; from the response to pass it as input. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function sBTargetingGetTargetableASINCountsAsyncWithHttpInfo($body, $amazon_advertising_api_client_id, $amazon_advertising_api_scope)
    {
        $returnType = '\AmazonAdvertisingApi\Model\SBTargetingGetTargetableASINCountsResponseContent';
        $request = $this->sBTargetingGetTargetableASINCountsRequest($body, $amazon_advertising_api_client_id, $amazon_advertising_api_scope);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'sBTargetingGetTargetableASINCounts'
     *
     * @param  \AmazonAdvertisingApi\Model\SBTargetingGetTargetableASINCountsRequestContent $body (required)
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a &#x60;Login with Amazon&#x60; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header and choose profile id &#x60;profileId&#x60; from the response to pass it as input. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function sBTargetingGetTargetableASINCountsRequest($body, $amazon_advertising_api_client_id, $amazon_advertising_api_scope)
    {
        // verify the required parameter 'body' is set
        if ($body === null || (is_array($body) && count($body) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $body when calling sBTargetingGetTargetableASINCounts'
            );
        }
        // verify the required parameter 'amazon_advertising_api_client_id' is set
        if ($amazon_advertising_api_client_id === null || (is_array($amazon_advertising_api_client_id) && count($amazon_advertising_api_client_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_advertising_api_client_id when calling sBTargetingGetTargetableASINCounts'
            );
        }
        // verify the required parameter 'amazon_advertising_api_scope' is set
        if ($amazon_advertising_api_scope === null || (is_array($amazon_advertising_api_scope) && count($amazon_advertising_api_scope) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_advertising_api_scope when calling sBTargetingGetTargetableASINCounts'
            );
        }

        $resourcePath = '/sb/targets/products/count';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // header params
        if ($amazon_advertising_api_client_id !== null) {
            $headerParams['Amazon-Advertising-API-ClientId'] = ObjectSerializer::toHeaderValue($amazon_advertising_api_client_id);
        }
        // header params
        if ($amazon_advertising_api_scope !== null) {
            $headerParams['Amazon-Advertising-API-Scope'] = ObjectSerializer::toHeaderValue($amazon_advertising_api_scope);
        }


        // body params
        $_tempBody = null;
        if (isset($body)) {
            $_tempBody = $body;
        }

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/vnd.sbtargeting.v4+json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/vnd.sbtargeting.v4+json'],
                ['application/vnd.sbtargeting.v4+json']
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\Query::build($formParams);
            }
        }


        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\Query::build($queryParams);
        return new Request(
            'POST',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation sBTargetingGetTargetableCategories
     *
     * Get targetable categories
     *
     * @param  \AmazonAdvertisingApi\Model\SBTargetingSupplySource $supply_source The supply source where the target will be used. Use &#x60;AMAZON&#x60; for placements on Amazon website. Use &#x60;STREAMING_VIDEO&#x60; for off-site video placements such as IMDb TV. (required)
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a &#x60;Login with Amazon&#x60; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header and choose profile id &#x60;profileId&#x60; from the response to pass it as input. (required)
     * @param  \AmazonAdvertisingApi\Model\SBTargetingLocale $locale The locale to which the caller wishes to translate the targetable categories or refinements to. For example, if the caller wishes to receive the targetable categories in Simplified Chinese, the locale parameter should be set to zh_CN. If no locale is provided, the returned tagetable categories will be in the default language of the marketplace. (optional)
     * @param  bool $include_only_root_categories Indicates whether to only retun root categories or not. (optional)
     * @param  string $parent_category_refinement_id Returns child categories of category. (optional)
     * @param  string $next_token Operations that return paginated results include a pagination token in this field. To retrieve the next page of results, call the same operation and specify this token in the request. If the &#x60;NextToken&#x60; field is empty, there are no further results. (optional)
     *
     * @throws \AmazonAdvertisingApi\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \AmazonAdvertisingApi\Model\SBTargetingGetTargetableCategoriesResponseContent
     */
    public function sBTargetingGetTargetableCategories($supply_source, $amazon_advertising_api_client_id, $amazon_advertising_api_scope, $locale = null, $include_only_root_categories = null, $parent_category_refinement_id = null, $next_token = null)
    {
        list($response) = $this->sBTargetingGetTargetableCategoriesWithHttpInfo($supply_source, $amazon_advertising_api_client_id, $amazon_advertising_api_scope, $locale, $include_only_root_categories, $parent_category_refinement_id, $next_token);
        return $response;
    }

    /**
     * Operation sBTargetingGetTargetableCategoriesWithHttpInfo
     *
     * Get targetable categories
     *
     * @param  \AmazonAdvertisingApi\Model\SBTargetingSupplySource $supply_source The supply source where the target will be used. Use &#x60;AMAZON&#x60; for placements on Amazon website. Use &#x60;STREAMING_VIDEO&#x60; for off-site video placements such as IMDb TV. (required)
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a &#x60;Login with Amazon&#x60; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header and choose profile id &#x60;profileId&#x60; from the response to pass it as input. (required)
     * @param  \AmazonAdvertisingApi\Model\SBTargetingLocale $locale The locale to which the caller wishes to translate the targetable categories or refinements to. For example, if the caller wishes to receive the targetable categories in Simplified Chinese, the locale parameter should be set to zh_CN. If no locale is provided, the returned tagetable categories will be in the default language of the marketplace. (optional)
     * @param  bool $include_only_root_categories Indicates whether to only retun root categories or not. (optional)
     * @param  string $parent_category_refinement_id Returns child categories of category. (optional)
     * @param  string $next_token Operations that return paginated results include a pagination token in this field. To retrieve the next page of results, call the same operation and specify this token in the request. If the &#x60;NextToken&#x60; field is empty, there are no further results. (optional)
     *
     * @throws \AmazonAdvertisingApi\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \AmazonAdvertisingApi\Model\SBTargetingGetTargetableCategoriesResponseContent, HTTP status code, HTTP response headers (array of strings)
     */
    public function sBTargetingGetTargetableCategoriesWithHttpInfo($supply_source, $amazon_advertising_api_client_id, $amazon_advertising_api_scope, $locale = null, $include_only_root_categories = null, $parent_category_refinement_id = null, $next_token = null)
    {
        $returnType = '\AmazonAdvertisingApi\Model\SBTargetingGetTargetableCategoriesResponseContent';
        $request = $this->sBTargetingGetTargetableCategoriesRequest($supply_source, $amazon_advertising_api_client_id, $amazon_advertising_api_scope, $locale, $include_only_root_categories, $parent_category_refinement_id, $next_token);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if (!in_array($returnType, ['string','integer','bool'])) {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\SBTargetingGetTargetableCategoriesResponseContent',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\SBTargetingBadRequestExceptionResponseContent',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\SBTargetingUnauthorizedExceptionResponseContent',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 429:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\SBTargetingThrottlingExceptionResponseContent',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\SBTargetingInternalServerExceptionResponseContent',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation sBTargetingGetTargetableCategoriesAsync
     *
     * Get targetable categories
     *
     * @param  \AmazonAdvertisingApi\Model\SBTargetingSupplySource $supply_source The supply source where the target will be used. Use &#x60;AMAZON&#x60; for placements on Amazon website. Use &#x60;STREAMING_VIDEO&#x60; for off-site video placements such as IMDb TV. (required)
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a &#x60;Login with Amazon&#x60; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header and choose profile id &#x60;profileId&#x60; from the response to pass it as input. (required)
     * @param  \AmazonAdvertisingApi\Model\SBTargetingLocale $locale The locale to which the caller wishes to translate the targetable categories or refinements to. For example, if the caller wishes to receive the targetable categories in Simplified Chinese, the locale parameter should be set to zh_CN. If no locale is provided, the returned tagetable categories will be in the default language of the marketplace. (optional)
     * @param  bool $include_only_root_categories Indicates whether to only retun root categories or not. (optional)
     * @param  string $parent_category_refinement_id Returns child categories of category. (optional)
     * @param  string $next_token Operations that return paginated results include a pagination token in this field. To retrieve the next page of results, call the same operation and specify this token in the request. If the &#x60;NextToken&#x60; field is empty, there are no further results. (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function sBTargetingGetTargetableCategoriesAsync($supply_source, $amazon_advertising_api_client_id, $amazon_advertising_api_scope, $locale = null, $include_only_root_categories = null, $parent_category_refinement_id = null, $next_token = null)
    {
        return $this->sBTargetingGetTargetableCategoriesAsyncWithHttpInfo($supply_source, $amazon_advertising_api_client_id, $amazon_advertising_api_scope, $locale, $include_only_root_categories, $parent_category_refinement_id, $next_token)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation sBTargetingGetTargetableCategoriesAsyncWithHttpInfo
     *
     * Get targetable categories
     *
     * @param  \AmazonAdvertisingApi\Model\SBTargetingSupplySource $supply_source The supply source where the target will be used. Use &#x60;AMAZON&#x60; for placements on Amazon website. Use &#x60;STREAMING_VIDEO&#x60; for off-site video placements such as IMDb TV. (required)
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a &#x60;Login with Amazon&#x60; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header and choose profile id &#x60;profileId&#x60; from the response to pass it as input. (required)
     * @param  \AmazonAdvertisingApi\Model\SBTargetingLocale $locale The locale to which the caller wishes to translate the targetable categories or refinements to. For example, if the caller wishes to receive the targetable categories in Simplified Chinese, the locale parameter should be set to zh_CN. If no locale is provided, the returned tagetable categories will be in the default language of the marketplace. (optional)
     * @param  bool $include_only_root_categories Indicates whether to only retun root categories or not. (optional)
     * @param  string $parent_category_refinement_id Returns child categories of category. (optional)
     * @param  string $next_token Operations that return paginated results include a pagination token in this field. To retrieve the next page of results, call the same operation and specify this token in the request. If the &#x60;NextToken&#x60; field is empty, there are no further results. (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function sBTargetingGetTargetableCategoriesAsyncWithHttpInfo($supply_source, $amazon_advertising_api_client_id, $amazon_advertising_api_scope, $locale = null, $include_only_root_categories = null, $parent_category_refinement_id = null, $next_token = null)
    {
        $returnType = '\AmazonAdvertisingApi\Model\SBTargetingGetTargetableCategoriesResponseContent';
        $request = $this->sBTargetingGetTargetableCategoriesRequest($supply_source, $amazon_advertising_api_client_id, $amazon_advertising_api_scope, $locale, $include_only_root_categories, $parent_category_refinement_id, $next_token);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'sBTargetingGetTargetableCategories'
     *
     * @param  \AmazonAdvertisingApi\Model\SBTargetingSupplySource $supply_source The supply source where the target will be used. Use &#x60;AMAZON&#x60; for placements on Amazon website. Use &#x60;STREAMING_VIDEO&#x60; for off-site video placements such as IMDb TV. (required)
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a &#x60;Login with Amazon&#x60; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header and choose profile id &#x60;profileId&#x60; from the response to pass it as input. (required)
     * @param  \AmazonAdvertisingApi\Model\SBTargetingLocale $locale The locale to which the caller wishes to translate the targetable categories or refinements to. For example, if the caller wishes to receive the targetable categories in Simplified Chinese, the locale parameter should be set to zh_CN. If no locale is provided, the returned tagetable categories will be in the default language of the marketplace. (optional)
     * @param  bool $include_only_root_categories Indicates whether to only retun root categories or not. (optional)
     * @param  string $parent_category_refinement_id Returns child categories of category. (optional)
     * @param  string $next_token Operations that return paginated results include a pagination token in this field. To retrieve the next page of results, call the same operation and specify this token in the request. If the &#x60;NextToken&#x60; field is empty, there are no further results. (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function sBTargetingGetTargetableCategoriesRequest($supply_source, $amazon_advertising_api_client_id, $amazon_advertising_api_scope, $locale = null, $include_only_root_categories = null, $parent_category_refinement_id = null, $next_token = null)
    {
        // verify the required parameter 'supply_source' is set
        if ($supply_source === null || (is_array($supply_source) && count($supply_source) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $supply_source when calling sBTargetingGetTargetableCategories'
            );
        }
        // verify the required parameter 'amazon_advertising_api_client_id' is set
        if ($amazon_advertising_api_client_id === null || (is_array($amazon_advertising_api_client_id) && count($amazon_advertising_api_client_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_advertising_api_client_id when calling sBTargetingGetTargetableCategories'
            );
        }
        // verify the required parameter 'amazon_advertising_api_scope' is set
        if ($amazon_advertising_api_scope === null || (is_array($amazon_advertising_api_scope) && count($amazon_advertising_api_scope) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_advertising_api_scope when calling sBTargetingGetTargetableCategories'
            );
        }

        $resourcePath = '/sb/targets/categories';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        if ($locale !== null) {
            $queryParams['locale'] = ObjectSerializer::toQueryValue($locale, null);
        }
        // query params
        if ($supply_source !== null) {
            $queryParams['supplySource'] = ObjectSerializer::toQueryValue($supply_source, null);
        }
        // query params
        if ($include_only_root_categories !== null) {
            $queryParams['includeOnlyRootCategories'] = ObjectSerializer::toQueryValue($include_only_root_categories, null);
        }
        // query params
        if ($parent_category_refinement_id !== null) {
            $queryParams['parentCategoryRefinementId'] = ObjectSerializer::toQueryValue($parent_category_refinement_id, null);
        }
        // query params
        if ($next_token !== null) {
            $queryParams['nextToken'] = ObjectSerializer::toQueryValue($next_token, null);
        }
        // header params
        if ($amazon_advertising_api_client_id !== null) {
            $headerParams['Amazon-Advertising-API-ClientId'] = ObjectSerializer::toHeaderValue($amazon_advertising_api_client_id);
        }
        // header params
        if ($amazon_advertising_api_scope !== null) {
            $headerParams['Amazon-Advertising-API-Scope'] = ObjectSerializer::toHeaderValue($amazon_advertising_api_scope);
        }


        // body params
        $_tempBody = null;

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/vnd.sbtargeting.v4+json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/vnd.sbtargeting.v4+json'],
                []
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\Query::build($formParams);
            }
        }


        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\Query::build($queryParams);
        return new Request(
            'GET',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Create http client option
     *
     * @throws \RuntimeException on file opening failure
     * @return array of http client options
     */
    protected function createHttpClientOption()
    {
        $options = [];
        if ($this->config->getDebug()) {
            $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
            if (!$options[RequestOptions::DEBUG]) {
                throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
            }
        }

        return $options;
    }
}
